package com.guigu.qingcheng.controller;

import com.guigu.qingcheng.pojo.TbOrder;
import com.guigu.qingcheng.service.TbOrderService;
import com.guigu.qingcheng.service.WxPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("wxxpay")
public class WxxPayController {

    @Autowired
    private WxPayService wxPayService;

    @Autowired
    private TbOrderService orderService;


    @PostMapping("/createNative")
    public Map createNative(String orderId,String username){
        TbOrder byId = orderService.findById(orderId);
        if(byId!=null){
            if("0".equals(byId.getOrderStatus()) && "0".equals(byId.getPayStatus()) && username.equals(byId.getUsername()) ){
               return wxPayService.createNative(orderId,byId.getPayMoney(),"http://huangwentao.easy.echosite.cn/portal/notify");
            }else {
                return null;
            }

        }else {
            return null;
        }
    }


    @PostMapping("/notifyLogic")
    public void notifyLogic(String xml){
        wxPayService.notifyLogic(xml);
    }

}
